home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Applications / TCPExample / TCPExample.p next >
Text File  |  1997-07-18  |  2KB  |  93 lines

  1. program TCPExample;
  2.  
  3.     uses
  4.         TextUtils,
  5.         PreserveA5,
  6.         MyInitialization, TCPTypes, MyTransport, MyStripTelnetCodes, MyConnections, MyStartup,
  7.         MyGrowZones;
  8.  
  9.     var
  10.         quitNow: boolean;
  11.  
  12.     type
  13.         TCPExampleObject = object(LineConnectionObject)
  14.                 procedure LineAvailable (line: str255);
  15.                 override;
  16.                 procedure Established;
  17.                 override;
  18.                 procedure Destroy;
  19.                 override;
  20.                 function Create: OSStatus;
  21.                 override;
  22.                 procedure Failed (oe: OSStatus);
  23.                 override;
  24.             end;
  25.  
  26.     procedure TCPExampleObject.Failed (oe: OSStatus);
  27.     begin
  28.         writeln('Failed with error ', oe);
  29.         inherited Failed(oe);
  30.     end;
  31.     
  32.     procedure TCPExampleObject.Established;
  33.     begin
  34.         writeln('Connection Established, send username');
  35.         SendLine('peter');
  36.     end;
  37.  
  38.     function TCPExampleObject.Create: OSStatus;
  39.     begin
  40.         writeln('Create');
  41.         Create := inherited Create;
  42.     end;
  43.     
  44.     procedure TCPExampleObject.Destroy;
  45.     begin
  46.         writeln('Connection Closed');
  47.         inherited Destroy;
  48.     end;
  49.  
  50.     procedure TCPExampleObject.LineAvailable (line: str255);
  51.     begin
  52.         writeln('>', line);
  53.     end;
  54.  
  55.     procedure HandleEvents;
  56.         var
  57.             dummy: boolean;
  58.             er: eventRecord;
  59.     begin
  60.         dummy := WaitNextEvent(everyEvent, er, 15, nil);
  61.         if er.what = keyDown then begin
  62.             quitNow := true;
  63.         end;
  64.         IdleStartup;
  65.     end;
  66.  
  67.     var
  68.         err: OSStatus;
  69.         obj: TCPExampleObject;
  70.         msg: integer;
  71. begin
  72.     Initialization;
  73.     InitStartup;
  74.     quitNow := false;
  75.     
  76.     StartupPreserveA5;
  77.     StartupConnections;
  78.     ConfigureTransport(true);
  79.     ConfigureGrowZones( 30000 );
  80.     
  81.     err := Startup(msg);
  82.     if err = noErr then begin
  83.         new(obj);
  84.         obj.NewActiveConnection (0, 'sparky:79');
  85.         while not quitNow do begin
  86.             HandleEvents;
  87.         end;
  88.         FinishStartup;
  89.     end;
  90. end.
  91.  
  92.  
  93.